package cn.gson.crm.controller;

import cn.gson.crm.model.mapper.BusinessMapper;
import cn.gson.crm.model.pojos.Business;
import cn.gson.crm.model.pojos.Employee;
import cn.gson.crm.model.pojos.User;
import cn.gson.crm.model.service.EvectionService;
import com.alibaba.druid.support.json.JSONUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/de")
public class EvectionContract {
  @Autowired
  EvectionService evectionService;
  @Autowired
  BusinessMapper businessMapper;

  //查询和分页
  @RequestMapping("/Business")
  @ResponseBody
  public Map<String,Object> selectbusiness(Integer currentPage, Integer Pagesize){
    Page<Object> obj= PageHelper.startPage(currentPage,Pagesize);
    List<Business> businessList=evectionService.selectbusiness();
    Map<String,Object> map=new HashMap<>();
    map.put("total",obj.getTotal());
    map.put("row",businessList);
    return map;
  }
  //删除
  @RequestMapping("/update1")
  @ResponseBody
  public void update1(String businessId){
    System.out.println("id"+businessId);
    int id = Integer.parseInt(businessId);
    evectionService.update1("已作废",id);
 }
   //按条件查询
    @RequestMapping("/Business2")
    @ResponseBody
    public Map<String,Object> selectbusiness2(Integer currentPage, Integer Pagesize, String businessStartTime,String businessOverTime, String businessPlace, String businessName){
        Page<Object> obj= PageHelper.startPage(currentPage,Pagesize);
        Map<String,Object> map=new HashMap<>();
        List<Business> businessList2=evectionService.selectbusiness2(businessStartTime,businessOverTime,businessPlace,businessName);
        map.put("total",obj.getTotal());
        map.put("row",businessList2);
        return map;
    }
    //新增
    @RequestMapping("/addBusiness")
    @ResponseBody
    public void addBusiness(@RequestBody Business business, HttpSession session){
       business.setBusinessApprover(business.getEmployeeByYgId().getYname());
       evectionService.addBusiness(business,session);
    }
    //查询员工
    @RequestMapping("/selectEmployee2")
    @ResponseBody
    public List<Employee> selectEmployee(){ return evectionService.selectEmployee();}

}
